﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace isky.dapper
{
    public class ConnectionFactory
    {
        public static readonly string XRMDBName = "SQLServer";
        /// <summary>
        /// 创建数据库连接
        /// </summary>
        /// <returns>数据库连接对象</returns>
        public static IDbConnection CreateConnection()
        {
            IDbConnection conn = new SqlConnection(XRMDBName);
            conn.Open();
            return conn;
        }

        /// <summary>
        /// 创建数据库连接
        /// </summary>
        /// <param name="ConnectionName">数据库链接名称</param>
        /// <returns>数据库连接对象</returns>
        public static IDbConnection CreateConnection(string ConnectionName)
        {
            string sqlConnectionStr = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;
            IDbConnection conn = new SqlConnection(sqlConnectionStr);
            conn.Open();
            return conn;
        }
    }
}
